{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 92,
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from numpy import *\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "wine = pd.read_csv(\"q3_final_feature_importance.csv\",header=None)\n",
    "wine1 = wine.loc[:,0]\n",
    "wine2 = wine.loc[:,1]\n",
    "wine3 = wine.loc[:,2]\n",
    "wine4 = wine.loc[:,3]\n",
    "wine5 = wine.loc[:,4]\n",
    "wine1\n",
    "# wine1 = pd.read_csv(\"q3_final_feature_importance.csv\",header=0)\n",
    "# wine2 = pd.read_csv(\"q3_final_feature_importance.csv\",header=0)\n",
    "# wine3 = pd.read_csv(\"q3_final_feature_importance.csv\",header=0)\n",
    "# wine4 = pd.read_csv(\"q3_final_feature_importance.csv\",header=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0       0.4\n",
       "1      23.4\n",
       "2      23.4\n",
       "3      23.6\n",
       "4      18.4\n",
       "       ... \n",
       "499    38.6\n",
       "500    40.6\n",
       "501    23.4\n",
       "502    38.2\n",
       "503    18.2\n",
       "Name: 0, Length: 504, dtype: float64"
      ]
     },
     "metadata": {},
     "execution_count": 92
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "source": [
    "def rank(wine):\n",
    "\n",
    "    rank=wine.sort_values(ascending=False)\n",
    "    index=rank[:100].index\n",
    "    value = rank[:100].values\n",
    "    return index,value"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "source": [
    "index1,value1 = rank(wine1)\n",
    "index2,value2 = rank(wine2)\n",
    "index3,value3 = rank(wine3)\n",
    "index4,value4 = rank(wine4)\n",
    "index5,value5 = rank(wine5)\n",
    "if (index1==21).any() and (index2==21).any() and (index3==21).any() and (index4==21).any() and (index5==21).any():\n",
    "    print(666)\n",
    "print(index3,index4)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "666\n",
      "Int64Index([ 51, 365, 391, 436, 367, 438, 273, 264, 502, 220, 444, 390, 428,\n",
      "            441,  38, 101, 302, 335,   1,   2, 427, 402, 266, 435,  65, 425,\n",
      "            103,  21, 404, 416, 258, 386, 417, 497, 207, 329, 394, 305, 418,\n",
      "            194, 409,  22, 304,  41, 498, 197, 400, 286, 491, 238, 496, 200,\n",
      "            412, 170, 332,  57, 499, 407, 339,  39, 249,   3, 454,  44,  23,\n",
      "            382,   9, 263, 384, 362, 399, 269,  75, 315,  81, 192, 368, 408,\n",
      "            324, 236, 398, 439, 102, 414, 381,  93, 330,  82,   4,  64, 457,\n",
      "             69,  24, 183, 375, 260, 433, 326, 198,  20],\n",
      "           dtype='int64') Int64Index([502,  38,  73,  65, 441, 264,   2, 220,  40,  81,   1, 302, 439,\n",
      "            258, 238, 372, 390, 249, 263,  24, 330, 497, 352, 170,  92, 221,\n",
      "            329, 304, 455,  37, 365, 454, 436, 499,  82, 428, 236, 498,  91,\n",
      "            353,  23,  79,  83, 183, 305,  22,  39,  99,  96, 407, 438, 273,\n",
      "            324, 207,  70, 369, 453, 371, 396, 286, 417, 491,  77, 496,  75,\n",
      "            416, 100, 366, 315, 335,  21, 413, 269, 287,  28,  80, 332, 409,\n",
      "            339, 244, 326, 391, 414, 288, 402, 415,  29, 456, 362, 266,  20,\n",
      "             71,  97, 173, 382,  25,  41, 178, 373, 239],\n",
      "           dtype='int64')\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "source": [
    "index_same = []\n",
    "for i in range(len(index1)):\n",
    "    if (index2==index1[i]).any() and (index3==index1[i]).any() and (index4==index1[i]).any() and (index5==index1[i]).any():\n",
    "        index_same.append(index1[i])\n",
    "len(index_same)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "32"
      ]
     },
     "metadata": {},
     "execution_count": 95
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "source": [
    "win = pd.read_excel(\"RF_lgb_Relation.xlsx\",header=0)\n",
    "win0 = pd.read_csv(\"normalization_train_data.csv\",header=0)\n",
    "\n",
    "after_feature=win.loc[:49,'Rela删除后的RF'].values\n",
    "win1 = win0.loc[:,after_feature]\n",
    "win2 = win0.iloc[:,8:]\n",
    "all_fea = win2.columns\n",
    "# np.where(all_fea == after_feature[i] for i in range(len(after_feature)))\n",
    "fea50 = []\n",
    "for i in range(len(after_feature)):\n",
    "    fea50.append(list(np.where(all_fea == after_feature[i])))\n",
    "fear50=np.array(fea50).flatten()\n",
    "print(len(fear50))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "50\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "source": [
    "fea504=win2.columns\n",
    "fea504"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Index(['nAcid', 'ALogP', 'ALogp2', 'AMR', 'apol', 'naAromAtom', 'nAromBond',\n",
       "       'nAtom', 'nHeavyAtom', 'nH',\n",
       "       ...\n",
       "       'MW', 'WTPT-1', 'WTPT-2', 'WTPT-3', 'WTPT-4', 'WTPT-5', 'WPATH', 'WPOL',\n",
       "       'XLogP', 'Zagreb'],\n",
       "      dtype='object', length=504)"
      ]
     },
     "metadata": {},
     "execution_count": 111
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "source": [
    "index_same_ = []\n",
    "for i in range(len(index_same)):\n",
    "    if (index_same[i]==fear50).any():\n",
    "        index_same_.append(index_same[i])\n",
    "index_same_"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[238, 220, 39, 502, 302, 441, 439, 498, 391, 23, 438, 24, 38, 65, 365]"
      ]
     },
     "metadata": {},
     "execution_count": 100
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "source": [
    "fea15 = fea504[index_same_]\n",
    "fea15\n",
    "import csv\n",
    "f = open('fea15.csv','w',encoding='utf-8')\n",
    "csv_writer = csv.writer(f)\n",
    "\n",
    "\n",
    "csv_writer.writerow(fea15)\n",
    "# 5. 关闭文件\n",
    "f.close()"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "source": [
    "fea504[index_same_]"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "Index(['minHBa', 'SsOH', 'BCUTc-1h', 'XLogP', 'maxHBd', 'MDEC-33', 'MDEC-23',\n",
       "       'WTPT-4', 'ETA_Shape_Y', 'ATSc4', 'MDEC-22', 'ATSc5', 'BCUTc-1l',\n",
       "       'SCH-7', 'hmin'],\n",
       "      dtype='object')"
      ]
     },
     "metadata": {},
     "execution_count": 119
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.10",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.10 64-bit ('deeplearning': conda)"
  },
  "interpreter": {
   "hash": "a2441be928683876ab9582b799059e1f9f764e7f9dd2044f4d30ad5ffc1df7fc"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}